<?php
namespace Admin\Controller; 
use Org\Util;
/**
 * Description of LbsProjectAreaInfoController
 *
 * @author Myron
 */
class LbsProjectAreaInfoController extends AdminController {
    public function index($id=''){
        $name = I('name');
        $map['name'] = array('like', '%' . (string) $name . '%');
        $list = $this->lists('lbs_project_areainfo', $map);
        int_to_string($list);
        $this->assign('_list', $list); 
        $projectdata=M('lbs_project')->where(array('id'=>$id))->find();
        $this->assign('_data', $projectdata); 
        $this->meta_title = '标题';
        $this->display();
    }
    
    /**
    *添加
    * @author 曹梦龙 <138888611@qq.com>
    */

    public function add($id='',$pid='',$name='',$otherid='',$warehouseid='') {
            if (IS_POST) {
                $gr_lbs_project_areainfo = array( 
                        'pid'=>$pid,
                        'name'=>$name,
                        'otherid'=>$otherid,
                        'warehouseid'=>$warehouseid,
                        'status'=>1,
                        'delflag'=>0, 
                        'createat'=>NOW_TIME,
                ); 
           
                $id = M('lbs_project_areainfo')->add($gr_lbs_project_areainfo);
           
                if (!$id) {
                        $this->error('添加失败！');
                } else {
                        $this->success('添加成功！', U('index',array('id'=>$pid)));
                };
            } else { 
                $projectdata=M('lbs_project')->where(array('id'=>$id))->find(); 
                $this->assign('_data', $projectdata); 
                $this->display();
            }
    }
    
/**
*编辑
* @author 曹梦龙 <138888611@qq.com>
*/
public function edit($pid='',$id='',$name='',$otherid='',$warehouseid=''){
     if(IS_POST){
        $gr_lbs_project_areainfo = array( 
                'name'=>$name,
                'otherid'=>$otherid, 
                'warehouseid'=>$warehouseid,
                'updateat'=>NOW_TIME, 
        ); 
         if (!M('lbs_project_areainfo')->where(array('id' => $id))->save($gr_lbs_project_areainfo)) {
                $this->error('修改失败！');
        } else {
           
                $this->success('修改成功！',  U('index',array('id'=>$pid)));
        };
     }else{
        $data=M('lbs_project_areainfo')->where(array('id' => $id))->find();        
        $projectdata=M('lbs_project')->where(array('id'=>$data['pid']))->find();            
        $this->assign('_data', $projectdata); 
        $this->assign('data',$data);
        $this->display();
     }
 }

    /** 
    * 状态修改
    * @author 曹梦龙 <138888611@qq.com>
    */
    public function changeStatus($method = null, $id) {
       $id = is_array($id) ? implode(',', $id) : $id;
       if (empty($id)) {
           $this->error('请选择要操作的数据!');
       }
       $map['id'] = array('in', $id); 
       switch (strtolower($method)) {
           case 'forbid':
               $this->forbid('lbs_project_areainfo', $map);
               break;
           case 'resume':
               $this->resume('lbs_project_areainfo', $map);
               break;
           case 'delete':
               $this->delete('lbs_project_areainfo', $map);
               break;
           default:
               $this->error('lbs_project_areainfo');
       }
    }


}
